package com.eric.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.eric.domain.po.EquipTransferPhoto;
import com.eric.mapper.EquipTransferPhotoMapper;
import com.eric.service.IEquipTransferPhotoService;
import com.eric.utils.ServerBASEURL;
import com.github.yulichang.base.MPJBaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 设备转移表 服务实现类
 * </p>
 *
 * @author 新哥
 * @since 2024-04-04
 */
@Service
@Transactional
public class EquipTransferPhotoServiceImpl extends MPJBaseServiceImpl<EquipTransferPhotoMapper, EquipTransferPhoto> implements IEquipTransferPhotoService {

    @Override
    public void deleteByPhotoUrlList(List<String> photoUrlList) {
        List<EquipTransferPhoto>list=new ArrayList<>();
//        遍历photoUrlList
        for (String photoUrl : photoUrlList) {
            StrUtil.removePrefix(photoUrl, ServerBASEURL.BASEURL);
            EquipTransferPhoto equipTransferPhoto = lambdaQuery()
                    .eq(EquipTransferPhoto::getPhotoUrl, photoUrl)
                    .one();
            if (!BeanUtil.isEmpty(equipTransferPhoto)) {
                list.add(equipTransferPhoto);
            }
        }
//        如果列表不为空，执行数据库移除，否则什么都不做。
        if (!list.isEmpty()) {
            removeByIds(list);
        }
    }
}
